package com.platform.service.impl;

import com.alibaba.fastjson.JSON;
import com.platform.annotation.SysLog;
import com.platform.base.BaseService;
import com.platform.common.Const;
import com.platform.common.ServerResponse;
import com.platform.dao.*;
import com.platform.pojo.*;
import com.platform.pojo.Enum;
import com.platform.service.ISynDataService;
import com.platform.util.DateTimeUtil;
import com.platform.util.NumberUtil;
import com.platform.util.PropertiesUtil;
import com.platform.util.StringUtil;
import com.xiaoleilu.hutool.http.HttpUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Map;

@Service("iSynDataService")
public class SynDataServiceImpl extends BaseService implements ISynDataService {


    /**
     * 同步投标人企业基础数据 仅供同步数据使用
     * @param
     * @return
     */
    @SysLog("同步投标人企业基础数据")
    public ServerResponse<String> synPsac0001(){
        String result= HttpUtil.get(PropertiesUtil.getProperty("psac0001"),
                "UTF-8");
        int countNums = 0;
        Map resultMap = JSON.parseObject(result,Map.class);
        List<Map> mapList = (List<Map>)resultMap.get("data");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-DD hh:mm:ss");
        if(null != mapList && 0 < mapList.size()){
            for (int i = 0; i < mapList.size(); i++) {
                try {
                    Psac0001 psac0001 = new Psac0001();
                    psac0001.setSupplierCode(StringUtil.valueOfString(mapList.get(i).get("SUPPLIER_CODE")));
                    psac0001.setEnglishName(StringUtil.valueOfString(mapList.get(i).get("ENGLISE_NAME")));
                    psac0001.setChineseName(StringUtil.valueOfString(mapList.get(i).get("CHINESE_NAME")));
                    psac0001.setZoneFlag(NumberUtil.safeToNumber(mapList.get(i).get("ZONE_FLAG")));
                    psac0001.setStatus(NumberUtil.safeToNumber(mapList.get(i).get("STATUS")));
                    psac0001.setCompanyName(StringUtil.valueOfString(mapList.get(i).get("COMPANY_NAME")));
                    psac0001.setAddress(StringUtil.valueOfString(mapList.get(i).get("ADDRRESS")));
                    psac0001.setTelephone(StringUtil.valueOfString(mapList.get(i).get("TELEPHONE")));
                    psac0001.setLawer(StringUtil.valueOfString(mapList.get(i).get("LAWER")));
                    psac0001.setRegisterAssets(StringUtil.valueOfString(mapList.get(i).get("REGISTER_ASSETS")));
                    psac0001.setProsecutopmArea(StringUtil.valueOfString(mapList.get(i).get("PROSECUTION_AREA")));
                    psac0001.setRegisterOffice(NumberUtil.safeToNumber(mapList.get(i).get("REGISTERED_OFFICE")));
                    psac0001.setCompanyType1(NumberUtil.safeToNumber(mapList.get(i).get("COMPANY_TYPE1")));
                    psac0001.setIdcard(StringUtil.valueOfString(mapList.get(i).get("IDCARD")));
                    psac0001.setTaxRate(StringUtil.valueOfString(mapList.get(i).get("EXTRA3")));
                    psac0001.setAccountLinkman(StringUtil.valueOfString(mapList.get(i).get("ACCOUNT_LINKMAN")));
                    psac0001.setAccountLinkmanTel(StringUtil.valueOfString(mapList.get(i).get("ACCOUNT_LINKMAN_TEL")));
                    psac0001.setAccountLinkmanEmail(StringUtil.valueOfString(mapList.get(i).get("ACCOUNT_LINKMAN_EMAIL")));
                    String busiStartDate = StringUtil.valueOfString(mapList.get(i).get("BUSI_START_DATE"));
                    if(StringUtil.isNotEmpty(busiStartDate)){
                        psac0001.setBusiStartDate(sdf.parse(busiStartDate));
                    }
                    String busiEndDate = StringUtil.valueOfString(mapList.get(i).get("BUSI_END_DATE"));
                    if(StringUtil.isNotEmpty(busiEndDate)){
                        psac0001.setBusiEndDate(sdf.parse(busiEndDate));
                    }
                    String establishDate = StringUtil.valueOfString(mapList.get(i).get("ESTABLISH_DATE"));
                    if(StringUtil.isNotEmpty(establishDate)){
                        psac0001.setEstablishDate(sdf.parse(establishDate));
                    }

                    psac0001.setThreeInOneFlag(NumberUtil.safeToNumber(mapList.get(i).get("THREE_IN_ONE_FLAG")));
                    psac0001.setUscCode(StringUtil.valueOfString(mapList.get(i).get("USC_CODE")));
                    psac0001.setTaxpayerType(NumberUtil.safeToNumber(mapList.get(i).get("TAXPAYER_TYPE")));
                    psac0001.setRemarks(StringUtil.valueOfString(mapList.get(i).get("EXTRA4")));
                    psac0001.setVersion(NumberUtil.safeToNumber(mapList.get(i).get("RECORD_VERSION")));
                    if(psac0001Mapper.insert(psac0001) > 0){
                        countNums++;
                    }
                }catch (Exception e){
                    e.printStackTrace();
                    continue;
                }

            }
        }
        return ServerResponse.createBySuccess("同步投标人企业基础数据："+countNums);
    }

    /**
     * 同步投标人银行账户信息 仅供同步数据使用
     * @return
     */
    @SysLog("同步投标人银行账户信息")
    public ServerResponse<String> synPsac0002(){
        String result= HttpUtil.get(PropertiesUtil.getProperty("psac0002"),
                "UTF-8");
        int countNums = 0;
        Map resultMap = JSON.parseObject(result,Map.class);
        List<Map> mapList = (List<Map>)resultMap.get("data");
        if(null != mapList && 0 < mapList.size()){
            for (int i = 0; i < mapList.size(); i++) {
                try{
                    Psac0002 psac0002 = new Psac0002();
                    psac0002.setUsername(StringUtil.valueOfString(mapList.get(i).get("CREATE_USER")));
                    psac0002.setBankName(StringUtil.valueOfString(mapList.get(i).get("BANK_NAME")));
                    psac0002.setBankAdress(StringUtil.valueOfString(mapList.get(i).get("BANK_ADDRESS")));
                    psac0002.setBankAccount(StringUtil.valueOfString(mapList.get(i).get("BANK_ACCOUNT")));
                    psac0002.setAccountType(NumberUtil.safeToNumber(mapList.get(i).get("ACCOUNT_TYPE")));
                    psac0002.setBankType(NumberUtil.safeToNumber(mapList.get(i).get("BANK_TYPE")));
                    psac0002.setVersion(NumberUtil.safeToNumber(mapList.get(i).get("RECORD_VERSION")));
                    if(psac0002Mapper.insert(psac0002) > 0){
                        countNums++;
                    }
                }catch (Exception e){
                    continue;
                }
            }
        }
        return ServerResponse.createBySuccessMessage("同步投标人银行账户信息："+countNums);
    }

    /**
     * 同步投标人开票信息
     * @return
     */
    @SysLog("同步投标人开票信息")
    public ServerResponse<String> synPsac0009(){
        String result= HttpUtil.get(PropertiesUtil.getProperty("psac0009"),
                "UTF-8");
        int countNums = 0;
        Map resultMap = JSON.parseObject(result,Map.class);
        List<Map> mapList = (List<Map>)resultMap.get("data");
        if(null != mapList && 0 < mapList.size()){
            for (int i = 0; i < mapList.size(); i++) {
                try{
                    Psac0009 psac0009 = new Psac0009();
                    psac0009.setUsername(StringUtil.valueOfString(mapList.get(i).get("CREATE_USER")));
                    psac0009.setTaxNumber(StringUtil.valueOfString(mapList.get(i).get("TAX_NUMBER")));
                    psac0009.setCompanyAddress(StringUtil.valueOfString(mapList.get(i).get("COMPANY_ADDRESS")));
                    psac0009.setPhone(StringUtil.valueOfString(mapList.get(i).get("PHONE")));
                    psac0009.setBankName(StringUtil.valueOfString(mapList.get(i).get("BANK_NAME")));
                    psac0009.setBankAccount(StringUtil.valueOfString(mapList.get(i).get("BANK_ACCOUNT")));
                    psac0009.setVersion(NumberUtil.safeToNumber(mapList.get(i).get("RECORD_VERSION")));
                    if(psac0009Mapper.insert(psac0009) > 0){
                        countNums++;
                    }
                }catch (Exception e){
                    continue;
                }
            }
        }
        return ServerResponse.createBySuccessMessage("同步投标人开票信息："+countNums);
    }

    /**
     * 同步用户注册基本信息
     * @return
     */
    @SysLog("同步用户注册基本信息")
    public ServerResponse<String> synUserInfo(){
        String result= HttpUtil.get(PropertiesUtil.getProperty("userData"),
                "UTF-8");
        int countNums = 0;
        Map resultMap = JSON.parseObject(result,Map.class);
        List<Map> mapList = (List<Map>)resultMap.get("data");
        if(null != mapList && 0 < mapList.size()){
            for (int i = 0; i < mapList.size(); i++) {
                User user = new User();
                user.setUsername(StringUtil.valueOfString(mapList.get(i).get("name")));
                user.setDisplayName(StringUtil.valueOfString(mapList.get(i).get("DISPLAY_NAME")));
                user.setPassword(StringUtil.valueOfString(mapList.get(i).get("CODED_PASSWORD")));
                user.setEmail(StringUtil.valueOfString(mapList.get(i).get("EMAIL")));
                user.setPhone(StringUtil.valueOfString(mapList.get(i).get("MOBILE_PHONE")));
                user.setRemark(StringUtil.valueOfString(mapList.get(i).get("DESC_INFO")));
                if(userMapper.insert(user) > 0){
                    countNums++;
                }
            }
        }
        return ServerResponse.createBySuccessMessage("同步用户注册基本信息："+countNums);
    }


    /**
     * 同步角色信息
     * @return
     */
    @SysLog("同步角色信息")
    public ServerResponse<String> synRole(){
        String result= HttpUtil.get(PropertiesUtil.getProperty("roleData"),
                "UTF-8");
        int countNums = 0;
        Map resultMap = JSON.parseObject(result,Map.class);
        List<Map> mapList = (List<Map>)resultMap.get("data");
        if(null != mapList && 0 < mapList.size()){
            for (int i = 0; i < mapList.size(); i++) {
                Role role = new Role();
                role.setRoleName(StringUtil.valueOfString(mapList.get(i).get("role_name")));
                role.setRoleCode(StringUtil.valueOfString(mapList.get(i).get("role_code")));
                if(roleMapper.insert(role) > 0){
                    countNums++;
                }
            }
        }
        return ServerResponse.createBySuccessMessage("同步角色信息："+countNums);
    }

    /**
     * 同步用户角色信息
     * @return
     */
    @SysLog("同步用户角色信息")
    public ServerResponse<String> synUserRole(){
        String result= HttpUtil.get(PropertiesUtil.getProperty("userRole"),
                "UTF-8");
        int countNums = 0;
        Map resultMap = JSON.parseObject(result,Map.class);
        List<Map> mapList = (List<Map>)resultMap.get("data");
        if(null != mapList && 0 < mapList.size()) {
            for (int i = 0; i < mapList.size(); i++) {
                UserRole userRole = new UserRole();
                userRole.setRoleCode(StringUtil.valueOfString(mapList.get(i).get("role_code")));
                if(userRole.getRoleCode().length() > 10){
                    continue;
                }
                userRole.setUsername(StringUtil.valueOfString(mapList.get(i).get("user_name")));
                if(userRoleMapper.insert(userRole) > 0){
                    countNums++;
                }
            }
        }
        return ServerResponse.createBySuccessMessage("同步用户角色信息："+countNums);
    }

    /**
     * 同步专家信息
     * @return
     */
    @SysLog("同步专家信息")
    public ServerResponse<String> synPsad0001(){
        String result= HttpUtil.get(PropertiesUtil.getProperty("psad0001"),
                "UTF-8");
        int countNums = 0;
        Map resultMap = JSON.parseObject(result,Map.class);
        List<Map> mapList = (List<Map>)resultMap.get("data");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-DD hh:mm:ss");
        if(null != mapList && 0 < mapList.size()) {
            for (int i = 0; i < mapList.size(); i++) {
                try{
                    Psad0001 psad0001 = new Psad0001();
                    psad0001.setCode(StringUtil.valueOfString(mapList.get(i).get("CODE")));
                    psad0001.setName(StringUtil.valueOfString(mapList.get(i).get("NAME")));
                    psad0001.setIdCardType(StringUtil.valueOfString(mapList.get(i).get("ID_CARD_TYPE")));
                    psad0001.setIdCardCode(StringUtil.valueOfString(mapList.get(i).get("ID_CARD_CODE")));
                    psad0001.setSex(NumberUtil.safeToNumber(mapList.get(i).get("SEX")));
                    psad0001.setBirthYear(StringUtil.valueOfString(mapList.get(i).get("BIRTH_YEAY")));
                    psad0001.setBirthMonth(StringUtil.valueOfString(mapList.get(i).get("BIRTH_MONTH")));
                    psad0001.setBirthDate(StringUtil.valueOfString(mapList.get(i).get("BIRTH_DATE")));
                    psad0001.setProvince(StringUtil.valueOfString(mapList.get(i).get("PROVINCE")));
                    psad0001.setCity(StringUtil.valueOfString(mapList.get(i).get("CITY")));
                    psad0001.setGraduateSchoole(StringUtil.valueOfString(mapList.get(i).get("GRADUATE_SCHOOL")));
                    String graduate_date = StringUtil.valueOfString(StringUtil.valueOfString(mapList.get(i).get("GRADUATE_DATE")));
                    if(StringUtil.isNotEmpty(graduate_date.trim())){
                        psad0001.setGraduateDate(sdf.parse(graduate_date));
                    }
                    psad0001.setLearnSpeciality(StringUtil.valueOfString(mapList.get(i).get("LEARN_SPECIALITY")));
                    psad0001.setMoble(StringUtil.valueOfString(mapList.get(i).get("MOBLIE")));
                    psad0001.setTelphone(StringUtil.valueOfString(mapList.get(i).get("TELEPHONE")));
                    psad0001.setFax(StringUtil.valueOfString(mapList.get(i).get("FAX")));
                    psad0001.setEmail(StringUtil.valueOfString(mapList.get(i).get("EMAIL")));
                    psad0001.setAddress(StringUtil.valueOfString(mapList.get(i).get("ADDRESS")));
                    psad0001.setZip(StringUtil.valueOfString(mapList.get(i).get("ZIP")));
                    psad0001.setIsOnJob(NumberUtil.safeToNumber(mapList.get(i).get("IS_ON_JOB")));
                    psad0001.setWorkCompany(StringUtil.valueOfString(mapList.get(i).get("WORK_COMPANY")));
                    psad0001.setWorkDepartment(StringUtil.valueOfString(mapList.get(i).get("WORK_DEPARTMENT")));
                    psad0001.setDuty(StringUtil.valueOfString(mapList.get(i).get("DUTY")));
                    psad0001.setBusinessMaster(StringUtil.valueOfString(mapList.get(i).get("BUSINESS_MASTER")));
                    psad0001.setWordResume(StringUtil.valueOfString(mapList.get(i).get("WORK_RESUME")));
                    psad0001.setWorkTitle(StringUtil.valueOfString(mapList.get(i).get("WORK_TITLE")));
                    psad0001.setProQualificationCode(StringUtil.valueOfString(mapList.get(i).get("PRO_QUALIFICATION_CODE")));
                    psad0001.setTrainInfo(StringUtil.valueOfString(mapList.get(i).get("TRAIN_INFO")));
                    psad0001.setExamination(StringUtil.valueOfString(mapList.get(i).get("EXAMINATION")));
                    psad0001.setRecommendSheetFileId(StringUtil.valueOfString(mapList.get(i).get("RECOMMEND_SHEET_FILE_ID")));
                    psad0001.setStatus(NumberUtil.safeToNumber(mapList.get(i).get("STATUS")));
                    psad0001.setLevelInfo(StringUtil.valueOfString(mapList.get(i).get("LEVEL_INFO")));
                    String remove_date= StringUtil.valueOfString(mapList.get(i).get("REMOVE_DATE"));
                    if(StringUtil.isNotEmpty(remove_date.trim())){
                        psad0001.setRemoveDate(sdf.parse(remove_date));
                    }
                    psad0001.setRemoveReason(StringUtil.valueOfString(mapList.get(i).get("REMOVE_REASON")));
                    psad0001.setAgreementStatus(StringUtil.valueOfString(mapList.get(i).get("AGREEMENT_STATUS")));
                    psad0001.setSpecialityids(StringUtil.valueOfString(mapList.get(i).get("SPECIALITYIDS")));
                    psad0001.setSpecialtynames(StringUtil.valueOfString(mapList.get(i).get("SPECIALITYNAMES")));
                    psad0001.setBirthDate(StringUtil.valueOfString(mapList.get(i).get("BIRTHDAY")));
                    psad0001.setLanguageLevel(StringUtil.valueOfString(mapList.get(i).get("LANGUAGE_LEVEL")));
                    psad0001.setIsEmergency(StringUtil.valueOfString(mapList.get(i).get("IS_EMERGENCY")));
                    psad0001.setIsSecurity(StringUtil.valueOfString(mapList.get(i).get("IS_SECURITY")));
                    psad0001.setCreateUser(StringUtil.valueOfString(mapList.get(i).get("CREATE_USER")));
                    psad0001.setUpdateUser(StringUtil.valueOfString(mapList.get(i).get("UPDATE_USER")));
                    psad0001.setDeleteUser(StringUtil.valueOfString(mapList.get(i).get("DELETE_USER")));
                    String deleteDate = StringUtil.valueOfString(mapList.get(i).get("DELETE_USER"));
                    if(StringUtil.isNotEmpty(deleteDate.trim())){
                        psad0001.setDeleteDate(sdf.parse(deleteDate));
                    }
                    psad0001.setActiveFlag(NumberUtil.safeToNumber(mapList.get(i).get("ACTIVE_FLAG")));
                    psad0001.setExtra1(StringUtil.valueOfString(mapList.get(i).get("EXTRA1")));
                    psad0001.setExtra2(StringUtil.valueOfString(mapList.get(i).get("EXTRA2")));
                    psad0001.setHighEducatignBackground(StringUtil.valueOfString(mapList.get(i).get("HIGH_EDUCATION_BACKGROUND")));
                    psad0001.setEmploymentYear(StringUtil.valueOfString(mapList.get(i).get("EMPLOYMENT_YEAR")));
                    psad0001.setEducationCertificateNo(StringUtil.valueOfString(mapList.get(i).get("EDUCATION_CERTIFICATE_NO")));
                    psad0001.setProQualificationNo(StringUtil.valueOfString(mapList.get(i).get("PRO_QUALIFICATION_NO")));
                    psad0001.setRegisterNo(StringUtil.valueOfString(mapList.get(i).get("REGISTER_NO")));
                    if(psad0001Mapper.insert(psad0001) > 0){
                        countNums++;
                    }

                }catch (Exception e){
                    continue;
                }

            }
        }
        return ServerResponse.createBySuccessMessage("同步成功"+countNums);
    }

    /**
     * 同步招标人信息
     * @return
     */
    public ServerResponse<String> synPsaa0001(){
        String result= HttpUtil.get(PropertiesUtil.getProperty("psaa0001"),
                "UTF-8");
        int countNums = 0;
        Map resultMap = JSON.parseObject(result,Map.class);
        List<Map> mapList = (List<Map>)resultMap.get("data");
        if(null != mapList && 0 < mapList.size()) {
            for (int i = 0; i < mapList.size(); i++) {
                try{
                    Psaa0001 psaa0001 = new Psaa0001();
                    psaa0001.setUsername(StringUtil.valueOfString(mapList.get(i).get("CUSTOMER_CODE")));
                    psaa0001.setCustomerName(StringUtil.valueOfString(mapList.get(i).get("CUSTOMER_NAME")));
                    psaa0001.setAddress(StringUtil.valueOfString(mapList.get(i).get("ADDRESS")));
                    psaa0001.setZip(StringUtil.valueOfString(mapList.get(i).get("ZIP")));
                    psaa0001.setTel(StringUtil.valueOfString(mapList.get(i).get("TEL")));
                    psaa0001.setFax(StringUtil.valueOfString(mapList.get(i).get("FAX")));
                    psaa0001.setUrl(StringUtil.valueOfString(mapList.get(i).get("URL")));
                    psaa0001.setEmail(StringUtil.valueOfString(mapList.get(i).get("EMAIL")));
                    psaa0001.setLawer(StringUtil.valueOfString(mapList.get(i).get("LAWER")));
                    psaa0001.setStatus(NumberUtil.safeToNumber(mapList.get(i).get("STATUS")));
                    psaa0001.setCompanyInstitution(NumberUtil.safeToNumber(mapList.get(i).get("COMPANY_INSTITUTION")));
                    String busiStartDate = StringUtil.valueOfString(mapList.get(i).get("BUSI_START_DATE"));
                    if(StringUtil.isNotEmpty(busiStartDate.trim())){
                        psaa0001.setBusiStartDate(DateTimeUtil.strToDate(busiStartDate));
                    }
                    String busiEndDate = StringUtil.valueOfString(mapList.get(i).get("BUSI_END_DATE"));
                    if(StringUtil.isNotEmpty(busiEndDate.trim())){
                        psaa0001.setBusiEndDate(DateTimeUtil.strToDate(busiEndDate));
                    }
                    psaa0001.setRegisterAssets(StringUtil.valueOfString(mapList.get(i).get("REGISTER_ASSETS")));
                    psaa0001.setRegisterAssetsCurrency(StringUtil.valueOfString(mapList.get(i).get("REGISTER_ASSETS_CURRENCY")));
                    psaa0001.setDeclarePerson(StringUtil.valueOfString(mapList.get(i).get("DECLARE_PERSON")));
                    psaa0001.setDeclareMoble(StringUtil.valueOfString(mapList.get(i).get("DECLARE_MOBILE")));
                    psaa0001.setDeclareEmail(StringUtil.valueOfString(mapList.get(i).get("DECLARE_EMAIL")));
                    psaa0001.setCreateUser(StringUtil.valueOfString(mapList.get(i).get("CREATE_USER")));
                    psaa0001.setUpdateUser(StringUtil.valueOfString(mapList.get(i).get("UPDATE_USER")));
                    psaa0001.setActiveFlag(NumberUtil.safeToNumber(mapList.get(i).get("ACTIVE_FLAG")));
                    String busiOperationStartDate = StringUtil.valueOfString(mapList.get(i).get("BUSI_OPERATION_START_DATE"));
                    if(StringUtil.isNotEmpty(busiOperationStartDate.trim())){
                        psaa0001.setBusiOperationStartDate(DateTimeUtil.strToDate(busiOperationStartDate));
                    }
                    String busiOperationEndDate = StringUtil.valueOfString(mapList.get(i).get("BUSI_OPERATION_END_DATE"));
                    if(StringUtil.isNotEmpty(busiOperationEndDate.trim())){
                        psaa0001.setBusiOperationEndDate(DateTimeUtil.strToDate(busiOperationEndDate));
                    }
                    psaa0001.setBusiOperationNum(StringUtil.valueOfString(mapList.get(i).get("BUSI_OPERATION_NUM")));
                    String lcnsPrctcStartDate = StringUtil.valueOfString(mapList.get(i).get("LCNS_PRCTC_START_DATE"));
                    if(StringUtil.isNotEmpty(lcnsPrctcStartDate.trim())){
                        psaa0001.setLcnsPrctcStartDate(DateTimeUtil.strToDate(lcnsPrctcStartDate));
                    }
                    String lcnsPrctcEndDate = StringUtil.valueOfString(mapList.get(i).get("LCNS_PRCTC_END_DATE"));
                    if(StringUtil.isNotEmpty(lcnsPrctcEndDate.trim())){
                        psaa0001.setLcnsPrctcEndDate(DateTimeUtil.strToDate(lcnsPrctcEndDate));
                    }
                    psaa0001.setBedNum(StringUtil.valueOfString(mapList.get(i).get("BED_NUM")));
                    psaa0001.setOwnership(NumberUtil.safeToNumber(mapList.get(i).get("OWNERSHIP")));
                    psaa0001.setSubjectionRelation(StringUtil.valueOfString(mapList.get(i).get("SUBJECTION_RELATION")));
                    psaa0001.setTheirCity(StringUtil.valueOfString(mapList.get(i).get("THEIR_CITY")));
                    psaa0001.setTheirCounty(StringUtil.valueOfString(mapList.get(i).get("THEIR_COUNTY")));
                    psaa0001.setMedicalType(StringUtil.valueOfString(mapList.get(i).get("MEDICAL_TYPE")));
                    psaa0001.setMedicalLevel(StringUtil.valueOfString(mapList.get(i).get("MEDICAL_LEVEL")));
                    psaa0001.setCompetebtOrg(StringUtil.valueOfString(mapList.get(i).get("COMPETENT_ORG")));
                    psaa0001.setProsecutionArea(StringUtil.valueOfString(mapList.get(i).get("PROSECUTION_AREA")));
                    psaa0001.setThreeInOneFlag(NumberUtil.safeToNumber(mapList.get(i).get("THREE_IN_ONE_FLAG")));
                    psaa0001.setUscCode(StringUtil.valueOfString(mapList.get(i).get("USC_CODE")));
                    if(psaa0001Mapper.insert(psaa0001) > 0){
                        countNums++;
                    }
                }catch (Exception e){
                    e.printStackTrace();
                    continue;
                }

            }
        }
        return ServerResponse.createBySuccess("保存成功"+countNums);
    }

    public ServerResponse<String> synPsad0002(String dictCode){
        String result= HttpUtil.get(PropertiesUtil.getProperty("psad0002")+dictCode,
                "UTF-8");
        int countNums = 0;
        Map resultMap = JSON.parseObject(result,Map.class);
        List<Map> mapList = (List<Map>)resultMap.get("data");
        if(null != mapList && 0 < mapList.size()) {
            for (int i = 0; i < mapList.size(); i++) {
                try{
                    Enum e = new Enum();
                    e.setType("public");
                    e.setCatalog("region");
                    e.setNames(StringUtil.valueOfString(mapList.get(i).get("item_name")));
                    e.setValues(StringUtil.valueOfString(mapList.get(i).get("item_code")));
                    if(enumMapper.insert(e) > 0){
                        countNums++;
                    }
                }catch (Exception e){
                    continue;
                }
            }
        }
        return ServerResponse.createBySuccessMessage("同步成功"+countNums);
    }

    /**
     * 同步设备价格数据
     * @return
     */
    @SysLog("同步设备价格数据")
    public ServerResponse<String> synMeprice(String startDate,String endDate){
        if(StringUtil.isEmpty(startDate) || StringUtil.isEmpty(endDate)){
            return ServerResponse.createByErrorMessage(Const.Msg.PARAMTERERROR);
        }
        String result = HttpUtil.get(PropertiesUtil.getProperty("meprice")+
                        "?key=hakfgadjfg78ada78qwh3jg&from="+startDate+"&to="+endDate,
                "UTF-8");
        int countNums = 0;
        Map resultMap = JSON.parseObject(result,Map.class);
        List<Map> mapList = (List<Map>)resultMap.get("data");
        if(null != mapList && 0 < mapList.size()) {
            //清除之前的数据
            mepriceMapper.truncateData();
            for (int i = 0; i < mapList.size(); i++) {
                try{
                    String zbdj = StringUtil.valueOfString(mapList.get(i).get("zbdj"));//中标单价
                    String zbje = StringUtil.valueOfString(mapList.get(i).get("zbje"));//中间金额
                    String xh = StringUtil.valueOfString(mapList.get(i).get("xh"));//型号
                    String pp = StringUtil.valueOfString(mapList.get(i).get("pp"));//品牌
                    if(StringUtil.isNotEmpty(zbdj) && StringUtil.isNotEmpty(zbje) &&
                            StringUtil.isNotEmpty(xh) && StringUtil.isNotEmpty(pp)){
                        Meprice meprice = new Meprice();
                        meprice.setTitlename(StringUtil.valueOfString(mapList.get(i).get("ggmc")));//公告名称
                        meprice.setEtype(StringUtil.valueOfString(mapList.get(i).get("sblx")));//设备类型
                        meprice.setEname(StringUtil.valueOfString(mapList.get(i).get("sbmc")));//设备名称
                        meprice.setNumbers(StringUtil.valueOfString(mapList.get(i).get("sl")));//数量
                        meprice.setZbprice(zbdj);
                        meprice.setZbmoney(zbje);
                        meprice.setSupplier(StringUtil.valueOfString(mapList.get(i).get("gys")));//供应商
                        meprice.setManufacturer(StringUtil.valueOfString(mapList.get(i).get("zzs")));//制造商
                        meprice.setBrand(StringUtil.valueOfString(mapList.get(i).get("pp")));//品牌
                        meprice.setModel(StringUtil.valueOfString(mapList.get(i).get("xh")));//型号
                        meprice.setBidtime(StringUtil.valueOfString(mapList.get(i).get("zbsj")));//中标时间
                        meprice.setTarea(StringUtil.valueOfString(mapList.get(i).get("zbdq")));//招标地区
                        meprice.setEuunit(StringUtil.valueOfString(mapList.get(i).get("sydw")));//设备使用单位
                        meprice.setAgency(StringUtil.valueOfString(mapList.get(i).get("dljg")));//代理机构
                        meprice.setBiddingmethod(StringUtil.valueOfString(mapList.get(i).get("zbfs")));//招标方式
                        if(mepriceMapper.insert(meprice) > 0){
                            countNums++;
                        }
                    }else{
                        continue;
                    }
                }catch (Exception e){
                    e.printStackTrace();
                    continue;
                }
            }
        }
        return ServerResponse.createBySuccessMessage("同步成功"+countNums);
    }

}
